﻿@using Presentation.Web.Admin
@model Domain.Dto.UserDto
@{
    ViewBag.subtitle = "修改用户";
    ViewBag.Title = "修改用户";
}
@using (Ajax.BeginForm("edit", "user", new AjaxOptions
{
    HttpMethod = "post",
    OnBegin = "checkedEditForm",
    OnFailure = "editFailure",
    OnSuccess = "editSuccess"
}))
{
    @Html.ValidationSummary(true)
    <fieldset class="module width_full">
        @Html.Partial("_Form", Model)
    </fieldset>
    <p>
        @{
    if (Html.HasUiPermission(this.ViewContext, "edit"))
    { 
            <input type="submit" value="修改" class='alt_btn module_margin' />@Html.GoBackPre("t-button")
    }
        }
    </p>
}
<div>
</div>
<script type="text/javascript">
    $(function () {
        $('#customSex').change(function () {
            var res = $(this).val();
            if (res == 1) {
                $('#Sex').val("true");
            } else if (res == 2) {
                $('#Sex').val("false");
            } else {
                $('#Sex').val("true");
            }
        });
    });

    function checkedEditForm() {
        var res = true;
        if ($('#UserName').val() == 0) {
            $('#UserName').focus();
            alert("用户名不能为空");
            res = false;
            return res;
        }
        if ($('#customSex').val() == 0) {
            alert("请选择性别");
            $('#customSex').focus();
            res = false;
            return res;
        }
        return res;
    }

    function editSuccess(res) {
        if (res.success) {
            alert("修改成功");
        }
        else {
            alert(res.message);
        }
    }

    function editFailure() {
        alert("修改失败了T_T！");
    }
</script>
